﻿@model PNProject.Models.LocationModel

@{
    ViewBag.Title = "Create";
    Layout = "~/Views/Shared/AdminLayout.cshtml";
}

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="/Scripts/jquery-1.5.1.js" type="text/javascript"></script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<div style="width:785px; height:25px; background-color:#363530; color:White; padding-left:10px; padding-top:5px;">
Tạo mới 1 locationss
</div>
<div style="padding:10px; width:775px; min-height:100px; overflow:hidden;">


    @using (Html.BeginForm("Create", "AdminMap", FormMethod.Post, new { enctype = "multipart/form-data", id="formsubmit" }))
    {
        @Html.ValidationSummary(true)
        <fieldset>
            <legend>Form nhập -Map banner</legend>
            <br />
            <div class="title">
                Dia chi
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.Address)
            </div>
            <br/>
            <p>
                <input id="main-submit" type="submit" value="Tạo mới" />
            </p>
        </fieldset>
        <input id="hidLat" type="hidden" name="lat"/>
        <input id="hidLng" type="hidden" name="lng"/>
    }

</div>

<script type="text/javascript">
    var geocoder;
    $(document).ready(function () {
        geocoder = new google.maps.Geocoder();
        $("#main-submit").click(function () {
            var address = $("#Address").val();
            if (address == '')
                alert("Nhap dia chi");
            else
                codeAddress(address);
            return false;
        });
       
    });
    function codeAddress(address) {
        geocoder.geocode({ 'address': address }, function (results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                var location = results[0].geometry.location;
                $("#hidLat").val(location.lat());
                $("#hidLng").val(location.lng());
                $("#formsubmit").submit();
                //alert(location.lat());
                //alert(location.lng());
            } else {
                alert('Geocode was not successful for the following reason: ' + status);
            }
        });
    }
</script>